#!/bin/bash
# install.sh  –  run on Rocky Linux 9.3
set -e
echo "========== 1. 安装 OpenJDK 17 =========="
dnf -y install java-17-openJDK java-17-openjdk-devel
java -version

echo "========== 2. 安装 Node.js 20 =========="
curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -
dnf -y install nodejs
node -v
npm -v

echo "========== 3. 安装 Jenkins LTS =========="
cat > /etc/yum.repos.d/jenkins.repo <<'EOF'
[jenkins]
name=Jenkins-stable
baseurl=https://pkg.jenkins.io/redhat-stable
gpgcheck=1
gpgkey=https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
EOF
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
dnf -y install jenkins
systemctl enable --now jenkins

echo "========== 4. 防火墙放行 8080 =========="
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload

echo "========== 5. 输出初始密码 =========="
sleep 5
echo "Jenkins initialAdminPassword:"
cat /var/lib/jenkins/secrets/initialAdminPassword